package com.xyazm.order.statemachine;

/** 售后订单状态机配置
 * @author xuyou
 * @date 2023年01月15日 19:43
 */
import com.xyazm.common.enums.OrderStatusChangeEnum;
import com.xyazm.common.enums.OrderStatusEnum;
import com.xyazm.order.enums.AfterSaleStateChangeEnum;
import com.xyazm.order.enums.AfterSaleStatusEnum;
import com.xyazm.order.statemachine.action.AfterSaleActionFactory;
import com.xyazm.order.statemachine.action.AfterSaleStateAction;
import com.xyazm.order.statemachine.action.OrderActionFactory;
import com.xyazm.order.statemachine.action.OrderStateAction;
import org.squirrelframework.foundation.fsm.annotation.StateMachineParameters;

@StateMachineParameters(stateType = AfterSaleStatusEnum.class,eventType = AfterSaleStateChangeEnum.class,contextType = Object.class)
public class AfterSaleStateMachine extends BaseStateMachine<AfterSaleStatusEnum, AfterSaleStateChangeEnum> {

    // 状态在流转到不同的状态的时候，就需要不同的action来触发
    private AfterSaleActionFactory afterSaleActionFactory;

    public void setAfterSaleActionFactory(AfterSaleActionFactory afterSaleActionFactory) {
        this.afterSaleActionFactory = afterSaleActionFactory;
    }

    @Override
    protected void onStateChangeInternal(AfterSaleStatusEnum fromStatus, AfterSaleStatusEnum toState, AfterSaleStateChangeEnum event, Object context) {
        // 真正触发状态流转的动作
        AfterSaleStateAction<?> action = afterSaleActionFactory.getAction(event);
        if (action != null) {
            action.onStateChange(event, context);
        }
    }


    @Override
    public void onStateChange(AfterSaleStatusEnum fromStatus, AfterSaleStatusEnum toStatus, AfterSaleStateChangeEnum event, Object context) {
        super.onStateChange(fromStatus, toStatus, event, context);
    }
}
